package com.zzyl.controller;


import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.IotService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
public class iotController {
    @Autowired
    private IotService iotService;

    /**
     * 同步IOT产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    public ResponseResult syncProductList(){
        iotService.syncProductList();
        return ResponseResult.success();
    }

    /**
     * 查询所有产品列表
     * @return
     */
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> selectAllProductList(){
        List<ProductVo> listVo = iotService.selectAllProductList();
        return ResponseResult.success(listVo);
    }

    /**
     * 新增设备
     * @param dto
     * @return
     */
    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto dto){
        iotService.registerDevice(dto);
        return ResponseResult.success();
    }

    /**
     *分页查询设备
     * @param dto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> findByPage(DevicePageQueryDto dto){
        PageResponse<DeviceVo> page = iotService.findByPage(dto);
        return ResponseResult.success(page);
    }

    /**
     * 查看设备详细信息
     * @param dto
     * @return
     */
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto dto){
        DeviceVo deviceVo = iotService.queryDeviceDetail(dto);
        return ResponseResult.success(deviceVo);
    }
}
